package com.wfh.adapter;

import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.wfh.R;
import com.wfh.activity.HomeActivity;
import com.wfh.activity.MyTicketsActivity;
import com.wfh.activity.TicketsActivity;
import com.wfh.bean.TicketsBean;
import com.wfh.util.Util;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class TicketsAdapter extends BaseAdapter {

	Context context;
	public ArrayList<TicketsBean> list;

	// private static HashMap<Integer, Boolean> IsSelected = new
	// HashMap<Integer, Boolean>();

	public TicketsAdapter(Context context, ArrayList<TicketsBean> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View view, ViewGroup arg2) {
		View adapter;
		LayoutInflater minflater = LayoutInflater.from(context);

		adapter = minflater.inflate(R.layout.adapter_tickets, null);
		TextView name = (TextView) adapter.findViewById(R.id.textView1);
		TextView money = (TextView) adapter.findViewById(R.id.textView2);
		TextView exp_date = (TextView) adapter.findViewById(R.id.textView4);
		Button qiang = (Button) adapter.findViewById(R.id.button1);
		qiang.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Bundle bd = new Bundle();
				bd.putString("id", list.get(position).getJuan_id());
				HomeActivity.service.qiangTickets(context,
						new Intent().putExtras(bd));
			}
		});

		name.setText(list.get(position).getJuan_name());
		money.setText(list.get(position).getReduce_money());
		exp_date.setText("有效期截止到:" + list.get(position).getExp_date());

		return adapter;
	}

	public void refresh(ArrayList<TicketsBean> list) {
		this.list = list;
		notifyDataSetChanged();
	}

}
